export const BASE_URL = '/blade-lis'

export const showToast = (title, duration = 2000, icon = 'none') => {
	uni.showToast({
		title: title,
		duration: duration,
		icon: icon,
		mask: true
	});
}
export const showLoading = (title) => {
	uni.showLoading({
		title: title,
		mask: true
	});
}

export const hideLoading = () => {
	uni.hideLoading()
}

// 获取当前月的第一天和最后一天日期 如：['2020-09-01 00:00:00','2020-09-30 23:59:59'] 
export const getMonthDay = (y, m) => {
	if (y && m) {
		let day = new Date(y, m, 0);
		return [`${y}-${m}-01 00:00:00`, `${y}-${m}-${day.getDate()} 23:59:59`]
	} else {
		let date = new Date();
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = new Date(year, month, 0);
		if (month < 10) {
			month = '0' + month
		}
		return [`${year}-${month}-01 00:00:00`, `${year}-${month}-${day.getDate()} 23:59:59`]
	}
}

// 获取某天00:00:00 到23:59:59
export const getDayTime = (y, m, d) => {
	if (y && m && d) {
		return [`${y}-${m}-${d} 00:00:00`, `${y}-${m}-${d} 23:59:59`]
	} else {
		let date = new Date();
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();
		if (day < 10) {
			day = "0" + day;
		}
		if (month < 10) {
			month = '0' + month
		}
		return [`${year}-${month}-${day} 00:00:00`, `${year}-${month}-${day} 23:59:59`]
	}
}

// 业务统计获取对应时间


export const getTime = (index, val) => {
	let startTime = ''
	let endTime = ''
	let selectDate = ''
	if (index == 0) {
		if (val) {
			startTime = getDayTime(val.year, val.month, val.day)[0]
			endTime = getDayTime(val.year, val.month, val.day)[1]
			selectDate = startTime.substr(0,10)
		} else {
			startTime = getDayTime()[0]
			endTime = getDayTime()[1]
			selectDate = startTime.substr(0,10)
		}
	} else if (index == 1) {
		if (val) {
			startTime = getMonthDay(val.year, val.month)[0]
			endTime = getMonthDay(val.year, val.month)[1]
			selectDate = startTime.substr(0,7)
		} else {
			startTime = getMonthDay()[0]
			endTime = getMonthDay()[1]
			selectDate = startTime.substr(0,7)
		}
	}
	return [startTime,endTime,selectDate]
}
